﻿using AntdUI;
using BST250301.Models;
using BST250301.Pages;
using BST250301TestStand.Models;
using BST250301TestStand.Models.Utils;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.VisualBasic;
using Mysqlx.Crud;
using NPOI.OpenXmlFormats.Wordprocessing;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using static System.ComponentModel.Design.ObjectSelectorEditor;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolBar;

namespace BST250301.Views
{
    public partial class Operate : UserControl
    {
        private AntdUI.Window window;
        public static AntList<ProjectItem> antList = new AntList<ProjectItem>();
        AntList<TemplateItem> antTemplateList = new AntList<TemplateItem>();
        int orderid = 1;
        public static bool IsBreak = false;
        bool IsRunning = false;
        bool IsPause = false;
        bool IsRecord = false;
        int IntPause = -99;
        int _rowid = 0;
        nint windowshandle;
        private AppDbContext appDbContext;
        public Operate()
        {
            InitializeComponent();
            InitTableColumns();
            BindEventHandler();
            InitData(MainWindow.configapp.PlanName, "");
            windowshandle = MainWindow.windowshandle;
            this.inputSN.Focus();
            this.inputSN.SelectAll();
        }

        private void BindEventHandler()
        {
            table_base.CellClick += Table_base_CellClick;
            table_base.CellDoubleClick += Table_base_DoubleCellClick;
            table_base.CellButtonClick += Table_base_CellButtonClick;
            btnStart.Click += async (sender, e) => await btnStart_Click();
            buttonPlan.Click += async (sender, e) => await buttonPlan_Click();
            PlanSelect.PlanChanged += PlanChange;
            if (!MainWindow.userCurrent.OperEnable)
            { this.Enabled = false; }
        }
        private async void InitData(string planname, string setname)
        {
            var plateList = DB.GetTestTemplate(planname);
            if (plateList.Count > 0)
            {
                antTemplateList = plateList;

                selectSetName.Items.Clear();
                foreach (var item in plateList)
                {
                    selectSetName.Items.Add(item.TestName);
                }
                if (string.IsNullOrEmpty(setname))
                {
                    selectSetName.Text = plateList.First().TestName;
                    setname = plateList.First().TestName;
                }
                else
                {
                    selectSetName.Text = setname;
                }
                antList = await GetProjectAndPlateList(setname);
                table_base.Binding(antList);
                table_base.Bordered = true;
            }
        }
        private void InitTableColumns()
        {
            table_base.Columns = new ColumnCollection() {
               //new AntdUI.Column("", "",ColumnAlign.Center){ Width ="100"},
                new AntdUI.ColumnCheck("IsChecked","选中"){Width ="100",Title="    启用"},
                new AntdUI.Column("OrderID", "序号",ColumnAlign.Center){ Width ="150"},
                new AntdUI.Column("Name", "项目名称",ColumnAlign.Left){ Width ="675"},
                //new AntdUI.Column("Description", "项目描述",ColumnAlign.Center){ Width ="200",LineBreak = true,},
                //new AntdUI.Column("TemperatureOil", "设定油温",ColumnAlign.Center),
                //new AntdUI.Column("ClutchState", "设定离合器状态",ColumnAlign.Center),
                //new AntdUI.Column("MasterGearPosition", "设定主挡位",ColumnAlign.Center),
                //new AntdUI.Column("SlaveGearPosition", "设定副挡位",ColumnAlign.Center),
                //new AntdUI.Column("RotateSeeped", "设定转速",ColumnAlign.Center),
                ////new AntdUI.Column("TestCondition", "前置条件",ColumnAlign.Center),
                //new AntdUI.Column("OfterCondition", "后置条件",ColumnAlign.Center),
                //new AntdUI.Column("Processing", "进度",ColumnAlign.Center),
                //new AntdUI.Column("Note", "备注",ColumnAlign.Center),
                new AntdUI.Column("CellLinks", "操作",ColumnAlign.Center){ Width ="150"},

            };
        }
        private void PlanChange(object? sender, string planname)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new EventHandler<string>(PlanChange), sender, planname);
                return;
            }
            InitData(planname, "");
        }
        /// <summary>
        /// 显示要执行项目列表
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private async Task<AntList<ProjectItem>> GetProjectAndPlateList(string name)
        {
            var list = new AntList<ProjectItem>();
            var result = DB.GetTemPlatestep(MainWindow.configapp.PlanName, name);
            int repeat = 1;
            foreach (var item in result)
            {
                if (item.TestName == name)
                    repeat = item.Repeat;
                if (item.ItemType == ProType.标准程序)
                {
                    var ret = DB.GetProjectListByCode(item.ProjectCode);
                    if (ret != null)
                    {
                        orderid = ret.OrderID = item.OrderID;
                        ret.PlanName = item.PlanName;
                        ret.TemplateName = item.TestName;

                        if (!string.IsNullOrEmpty(item.RecordData))
                        {
                            ret.ListRecordData = item.RecordData.Split(";").ToList();
                            foreach (var sbuitem in ret.ListRecordData)
                            {
                                var rec = DB.GetRecordDataByName(sbuitem);
                                if (rec != null)
                                    ret.ListRecord.Add(rec);
                            }
                        }
                        ret.IsChecked = true;
                        //以下step要加到数据库里
                        ret.RotateSpeed.IsStep = ret.RotateSpeed.StepKeep != 0 && ret.RotateSpeed.StepValue != 0 && ret.RotateSpeed.ValueStart != ret.RotateSpeed.ValueEnd;
                        ret.CFSetPointCurrent.IsStep = ret.CFSetPointCurrent.StepKeep != 0 && ret.CFSetPointCurrent.StepValue != 0 && ret.CFSetPointCurrent.ValueStart != ret.CFSetPointCurrent.ValueEnd;
                        ret.CRSetPointCurrent.IsStep = ret.CRSetPointCurrent.StepKeep != 0 && ret.CRSetPointCurrent.StepValue != 0 && ret.CRSetPointCurrent.ValueStart != ret.CRSetPointCurrent.ValueEnd;
                        ret.CPTOSetPointCurrent.IsStep = ret.CPTOSetPointCurrent.StepKeep != 0 && ret.CPTOSetPointCurrent.StepValue != 0 && ret.CPTOSetPointCurrent.ValueStart != ret.CPTOSetPointCurrent.ValueEnd;
                        ret.CellLinks = new CellLink[] { new CellButton("", "单步", TTypeMini.Primary) };

                        list.Add(ret);
                    }
                }
                else if (item.ItemType == ProType.前置延时)
                {
                    orderid = item.OrderID;

                    list.Add(new ProjectItem
                    {
                        IsChecked = true,
                        Name = item.ProjectName,
                        PlanName = item.PlanName,
                        TemplateName = item.TestName,
                        Description = "延时工序，其他参数无效",
                        Code = item.ProjectCode,
                        ItemType = item.ItemType,
                        ConfirmWay = item.ConfirmWay,
                        PreDelay = item.PreDelay,
                        AfterDelay = item.AfterDelay,
                        Mark = MainWindow.configapp.LoginUser,
                        ListRecordData = new List<string>(),
                        OrderID = item.OrderID,
                    });
                }
                else if (item.ItemType == ProType.后置延时)
                {
                    orderid = item.OrderID;

                    list.Add(new ProjectItem
                    {
                        IsChecked = true,
                        PlanName = item.PlanName,
                        TemplateName = item.TestName,
                        Name = item.ProjectName,
                        Description = "延时工序，其他参数无效",
                        Code = item.ProjectCode,
                        ItemType = item.ItemType,
                        ConfirmWay = item.ConfirmWay,
                        PreDelay = item.PreDelay,
                        AfterDelay = item.AfterDelay,
                        Mark = MainWindow.configapp.LoginUser,
                        OrderID = item.OrderID,
                        ListRecordData = new List<string>()
                    });
                }
            }
            return list;
        }
        /// <summary>
        /// 点击表格事件
        /// 运行时，自动回到正在执行项
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Table_base_CellClick(object sender, TableClickEventArgs e)
        {
            if (IsRunning)
            {
                if (table_base.SelectedIndex != _rowid)
                    table_base.SelectedIndex = _rowid;
                return;
            }
        }
        private void Table_base_DoubleCellClick(object sender, TableClickEventArgs e)
        {
            int cellindex = table_base.SelectedIndex - 1;
            if (cellindex < 0)
                return;
            if (IsRunning)
            {
                if (table_base.SelectedIndex != _rowid)
                    table_base.SelectedIndex = _rowid;
                return;
            }
            var item = antList[cellindex];
            var form = new ProjectEdit(window, item, false);// { Size = new Size(800, 500) };
            AntdUI.Modal.open(new AntdUI.Modal.Config("", form, TType.None)
            {
                BtnHeight = 0,
            });
            if (form.submit)
            {
                antList[cellindex] = item;
            }
        }
        /// <summary>
        /// 项目内停止按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Table_base_CellButtonClick(object sender, TableButtonEventArgs e)
        {
            var buttontext = e.Btn.Text;

            if (e.Record is ProjectItem item)
            {
                switch (buttontext)
                {
                    //暂不支持进入整行编辑，只支持指定单元格编辑，推荐使用弹窗或抽屉编辑整行数据
                    case "停止":
                        try
                        {
                            IntPause = table_base.SelectedIndex;
                            var selected = antList[IntPause - 1];
                            IsPause = true;
                            IsRecord = false;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show($"格式有错误，请检查后再试:{ex.Message}");
                        }
                        break;
                    case "单步":
                        try
                        {
                            IntPause = table_base.SelectedIndex;
                            var selected = antList[IntPause - 1];
                            selected.IsListFirst = true;
                            var show = new ShowInit("开始初始化...");
                            show.SetTopMost(this.Handle);
                            AntdUI.Modal.open(new AntdUI.Modal.Config("", show, TType.None) { BtnHeight = 0 });
                            if (!show.submit)
                            {
                                this.btnStart.Enabled = true;
                                StopInit();
                                ShowMessage($"已停止程序【{selectSetName.Text}】");
                                return;
                            }
                            var forwardItem = new ProjectItem() { };
                            var form = new ShowStatus(selected, forwardItem);
                            //form.TopMost = true;
                            //show.SetTopMost(windowshandle);
                            form.ShowDialog(this);

                            //form.Location = new Point(-100, -100);
                            ////form.Left = 1000;
                            ////form.Top = 800; 
                            //form.SetTopMost(windowshandle);
                            //window = MainWindow.mainwindow;
                            //window.Location = new Point(0,0);
                            //AntdUI.Modal.open(new AntdUI.Modal.Config("", form, TType.Success)
                            //{
                            //    BtnHeight = 0,
                            //});
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show($"格式有错误，请检查后再试:{ex.Message}");
                        }
                        break;
                }
            }
        }

        private async Task btnStart_Click()
        {
            if (!MainWindow.userCurrent.ApprovalEnable)
            {
                Process.GetCurrentProcess().Kill();
                //MessageBox.Show(window, "请输入新的注册码");
                return;
            }
            var form = new ShowDialog("确认执行？");// { Size = new Size(500, 350) };
            //form.SetTopMost(windowshandle);
            form.ShowDialog(); //AntdUI.Modal.open(new AntdUI.Modal.Config("", form, TType.None) { BtnHeight = 0 });
            if (!form.submit)
                return;
            if (string.IsNullOrEmpty(inputSN.Text))
            {
                form = new ShowDialog("当前SN为空，是否继续？");// { Size = new Size(500, 350) };
                form.ShowDialog();//                                  //form.SetTopMost(windowshandle);
                //AntdUI.Modal.open(new AntdUI.Modal.Config("", form, TType.None) { BtnHeight = 0 });
                if (!form.submit)
                    return;
            }

            //开始记录所有数据
            //ReadData.StartReadData(_listRecord);
            ShowMessage($"准备执行【{selectSetName.Text}】");

            table_base.RowSelectedBg = Color.Transparent;

            this.btnStart.Enabled = false;
            this.btnStop.Enabled = true;
            IsBreak = false;

#if DEBUG
            MessageBox.Show("调试模式，跳过驱动端初始化步骤");
#else
            var show = new ShowInit("开始初始化...");// { Size = new Size(500, 350) };
            //form.SetTopMost(windowshandle);
            AntdUI.Modal.open(new AntdUI.Modal.Config("", show, TType.None) { BtnHeight = 0 });
            if (!show.submit)
            {
                this.btnStart.Enabled = true;
                this.btnStop.Enabled = false;
                await StopInit();
                ShowMessage($"已停止程序【{selectSetName.Text}】");
                return;
            }

            //ShowMessage($"开始初始化驱动端准备工作【{selectSetName.Text}】");
            ////驱动端准备，并0转速,如果达到就返回true
            //bool ret = await Operation.StartOrStopEngineReady(true);
            //ShowMessage($"驱动端准备工作：【{ret}】，开始初始化离合状态【{selectSetName.Text}】");
            //ret = await Operation.StartClutchInit();
            //ShowMessage($"初始化离合状态：【{ret}】，开始执行程序【{selectSetName.Text}】");
#endif
            bool ret = await StartProces(antList);
            if (!ret)
            {
                table_base.SelectedIndex = 0;
                table_base.RowSelectedBg = Color.Transparent;
                IsBreak = true;
                //this.btnStop.Enabled = false;
            }
            await StopInit();
            this.btnStart.Enabled = true;
            this.btnStop.Enabled = false;
            ShowMessage($"已停止程序【{selectSetName.Text}】");
        }
        /// <summary>
        /// 初始化离合器状态（断开）
        /// 停止驱动器
        /// </summary>
        /// <returns></returns>
        private async Task<bool> StopInit()
        {
            try
            {
                await Operation.StartClutchInit();
                return await Operation.StartOrStopEngineReady(false);
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        private async Task<bool> StartProces(AntList<ProjectItem> list)
        {
            IsRunning = true;
            //times2++;
            ShowMessage($"开始【{selectSetName.Text}】");
            _rowid = 0;//行数
            bool isfirst = false;
            //foreach (var item in antList)
            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    var item = list[i];
                    _rowid++;
                    if (IsBreak)//如被中止，退出
                    {
                        IsRunning = false;
                        return false;
                    }
                    item.SN = this.inputSN.Text.Trim();

                    if (item.IsChecked)//如选中状态可执行
                    {
                        ShowMessage($"准备[{selectSetName.Text}]->【{item.Name}】");
                        if (item.ItemType == ProType.标准程序)
                        {
                            table_base.SelectedIndex = _rowid;// item.OrderID;
                            table_base.RowSelectedBg = Color.Green;


                            var forwardItem = new ProjectItem();
                            //等待状态符合要求
                            if (i > 0)
                            {
                                forwardItem = list[i - 1];
                            }
                            if (!isfirst)
                            {
                                isfirst = true;
                                item.IsListFirst = true;
                            }

                            var form = new ShowStatus(item, forwardItem);
                            //form.SetTopMost(windowshandle);
                            //form.TopMost = true;
                            //AntdUI.Modal.open(new AntdUI.Modal.Config("", form, TType.None)
                            //{
                            //    BtnHeight = 0,
                            //});

                            form.ShowDialog(this);
                            if (!form.submit)
                            {
                                IsRunning = false;
                                break;
                            }

                            //table_base.ScrollLine(item.OrderID-1);
                            table_base.RowSelectedBg = Color.GreenYellow;
                            //StartRecordData(item.ListRecordData);
                            ShowMessage($"正在进行[{selectSetName.Text}]->【{item.Name}】测试...");
                        }
                        else if (item.ItemType == ProType.前置延时)
                        {
                            var form = new ShowDialog(item.Name, item.PreDelay);
                            form.ShowDialog();//AntdUI.Modal.open(new AntdUI.Modal.Config("", form, TType.None) { BtnHeight = 0 });
                                              //for (int i = item.PreDelay; i > 0 && !IsBreak; i--)
                                              //{
                                              //    Thread.Sleep(1000);
                                              //    ShowMessage($"开始[{selectSetName.Text}]->【{item.Name}】{i}");
                                              //}
                        }
                    }
                }
                catch (Exception ex)
                {
                    var form = new ShowDialog($"正在进行[{selectSetName.Text}]测试发生错误", 10, true);
                    form.ShowDialog();//AntdUI.Modal.open(new AntdUI.Modal.Config("", form, TType.None) { BtnHeight = 0 });
                }
            }
            //是否需要增加系统初始化功能？断离合、停机？
            StopInit();

            //if (this._dataPLC.DriverSpeed < 900)
            //    Operation.SetCurrentChan(CurrentChannel.None);

            table_base.RowSelectedBg = Color.Gray;
            IsRunning = false;
            ShowMessage($"【{selectSetName.Text}】执行完毕");

            for (int i = 0; i < list.Count; i++)
            {
                bool ismode3 = false;
                string name = "";
                var item = list[i];
                if (!item.IsChecked)
                    continue;

                if (item.CFSetPointCurrent.SPCMode == 3)
                {
                    ismode3 = true;
                    name = "CF离合器KP压力测试";
                }
                else if (item.CRSetPointCurrent.SPCMode == 3)
                {
                    ismode3 = true;
                    name = "CR离合器KP压力测试";
                }
                else if (item.CPTOSetPointCurrent.SPCMode == 3)
                {
                    ismode3 = true;
                    name = "CPTO离合器KP压力测试";
                }
                if (ismode3)
                {
                    string maxP = item.SetPointCurrentKP.KPMaxPressure > 0 ? item.SetPointCurrentKP.KPMaxPressure.ToString("F4") : "未获取";
                    string maxAVG = item.SetPointCurrentKP.KPMaxAVGPressure > 0 ? item.SetPointCurrentKP.KPMaxAVGPressure.ToString("F4") : "未获取";
                    string okng = item.IsItemOKNG ? "OK" : "NG";
                    var overformKP = new ShowDialog($"【{name}】结果：" +
                        $"\r\n设置输入轴速度最大值：{item.SetPointCurrentKP.KPMaxOutSpeed} rpm" +
                        $"\r\n检测判读结果：{okng}" +
                        $"\r\n到达设置最大转速时的压力初值：{maxP} bar" +
                        $"\r\n维持设置最大转速时的压力均值：{maxAVG} bar");// { Size = new Size(500, 350) };
                    overformKP.SetTopMost(this.Handle);
                    overformKP.ShowDialog();
                }
            }




            var overform = new ShowDialog("当前程序执行完毕，立即查看曲线图？\r\n(曲线图为实时信息，当前窗口关闭即失效。历史数据已保存csv文件)");// { Size = new Size(500, 350) };
            overform.SetTopMost(this.Handle);
            overform.ShowDialog();
            //AntdUI.Modal.open(new AntdUI.Modal.Config("", overform, TType.None) { BtnHeight = 0 });
            if (overform.submit)
            {
                var form = new ShowRealList(antList.FirstOrDefault(), antList,false);// { Size = new Size(800, 500) };
                AntdUI.Modal.open(new AntdUI.Modal.Config("", form, TType.None)
                {
                    BtnHeight = 0,
                });
            }

            overform = new ShowDialog("当前程序执行完毕，是否查看即时报告？");// { Size = new Size(500, 350) };
            overform.SetTopMost(this.Handle);
            overform.ShowDialog();
            //AntdUI.Modal.open(new AntdUI.Modal.Config("", overform, TType.None) { BtnHeight = 0 });
            if (overform.submit)
            {
                var reportshow = new ReportShow(MainWindow.configapp.PlanName, selectSetName.Text, inputSN.Text, DateTime.Today);
                reportshow.ShowDialog();
            }
            return true;
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            DialogResult confirmResult = MessageBox.Show($"确认要停止当前程序【{selectSetName.Text}】吗？", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (confirmResult != DialogResult.Yes)
                return;
            StopInit();
            table_base.RowSelectedBg = Color.Transparent;
            IsBreak = true;
            this.btnStart.Enabled = true;
        }

        private async void selectSetName_SelectedIndexChanged(object sender, IntEventArgs e)
        {
            antList = await GetProjectAndPlateList(selectSetName.Text);
            table_base.Binding(antList);

            var plateList = DB.GetTestTemplate(MainWindow.configapp.PlanName);
            foreach (var item in plateList)
            {
                if (item.TestName == selectSetName.Text)
                {
                    break;
                }
            }
        }
        private void ShowMessage(string msg, bool hide = false)
        {
            // 确保在UI线程上更新控件
            if (this.InvokeRequired)
            {
                this.Invoke(new Action<string, bool>(ShowMessage), msg, hide);
                return;
            }
            if (listBox1.Items.Count > 1000)
                listBox1.Items.Clear();
            listBox1.Items.Add($"{DateTime.Now.ToLongTimeString()}---" + msg);
            listBox1.TopIndex = listBox1.Items.Count - 1;
        }

        private void btnRefrence_Click(object sender, EventArgs e)
        {
            InitData(MainWindow.configapp.PlanName, selectSetName.Text);
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (antList != null)
            {
                for (int i = 0; i < antList.Count; i++)
                {
                    antList[i].IsChecked = checkBox1.Checked;
                }
                table_base.Refresh();
            }
        }

        private void buttonGotoReport_Click(object sender, EventArgs e)
        {
            var reportshow = new ReportShow(MainWindow.configapp.PlanName, selectSetName.Text, inputSN.Text, DateTime.Today);
            reportshow.ShowDialog();
        }

        private async Task buttonPlan_Click()
        {
            if (!MainWindow.userCurrent.ApprovalEnable)
            {
                Process.GetCurrentProcess().Kill();
                //MessageBox.Show(window, "请输入新的注册码");
                return;
            }
            await StartPlanProcess();
        }
        private async Task StartPlanProcess()
        {
            if (antTemplateList != null)
            {
                if (!MainWindow.userCurrent.ApprovalEnable)
                {
                    Process.GetCurrentProcess().Kill();
                    return;
                }
                var form = new ShowDialog($"确认执行整个方案【{MainWindow.configapp.PlanName}】？");
                form.ShowDialog();
                if (!form.submit)
                    return;
                if (string.IsNullOrEmpty(inputSN.Text))
                {
                    form = new ShowDialog("当前SN为空，是否继续？");
                    form.ShowDialog();//                              

                    if (!form.submit)
                        return;
                }

                ShowMessage($"准备执行【{MainWindow.configapp.PlanName}】");

                table_base.RowSelectedBg = Color.Transparent;

                this.buttonPlan.Enabled = false;
                this.btnStart.Enabled = false;
                this.btnStop.Enabled = true;
                IsBreak = false;


                var show = new ShowInit("开始初始化...");
                AntdUI.Modal.open(new AntdUI.Modal.Config("", show, TType.None) { BtnHeight = 0 });
                if (!show.submit)
                {
                    this.buttonPlan.Enabled = true;
                    this.btnStart.Enabled = true;
                    this.btnStop.Enabled = false;
                    await StopInit();
                    ShowMessage($"已停止程序【{MainWindow.configapp.PlanName}】");
                    return;
                }

                for (int i = 0; i < antTemplateList.Count; i++)
                {
                    if (IsBreak)
                    {
                        break;
                    }
                    this.selectSetName.Text = antTemplateList[i].TestName;
                    antList = await GetProjectAndPlateList(antTemplateList[i].TestName);
                    table_base.Binding(antList);
                    await Task.Delay(500);
                    bool ret = await StartProces(antList);
                    if (!ret)
                    {

                        break;
                    }
                }
                {
                    table_base.SelectedIndex = 0;
                    table_base.RowSelectedBg = Color.Transparent;
                    IsBreak = true;
                    //this.btnStop.Enabled = false;
                }

                await StopInit();
                this.buttonPlan.Enabled = true;
                this.btnStart.Enabled = true;
                this.btnStop.Enabled = false;
                ShowMessage($"方案【{MainWindow.configapp.PlanName}】已测试完毕");
            }
        }

        private void buttonShowReal_Click(object sender, EventArgs e)
        {
            var form = new ShowRealList(antList.FirstOrDefault(), antList,false);// { Size = new Size(800, 500) };
            AntdUI.Modal.open(new AntdUI.Modal.Config("", form, TType.None)
            {
                BtnHeight = 0,
            });
        }
    }
}
